#include<malloc.h>
#include<iostream>
#include<vector>
using namespace std;

 struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};
int treesize(struct TreeNode* root)
{
    return root==NULL?0:treesize(root->left)+treesize(root->right)+1;
}

void postorder(struct TreeNode* root,int *a,int *pi)
{
    if(root==NULL)
    {
        return;
    }
    postorder(root->left,a,pi);
    postorder(root->right,a,pi);
    a[(*pi)++]=root->val;
}


int* postorderTraversal(struct TreeNode* root, int* returnSize){
    *returnSize=treesize(root);
    int *a=(int *)malloc(*returnSize*sizeof(int));
    int i=0;
    postorder(root,a,&i);
    return a;
}